vec2 fixuv(in vec2 uv){
  
  // vec2 p=10.*vec2(uv.x/iResolution.x*(iResolution.x/iResolution.y),abs(uv.y/iResolution.y-1.));
  vec2 p=(2.*uv-iResolution.xy)/iResolution.y;
  return p;
}

float sdCircle(in vec2 p,float r){
  return length(p)-r;
}

vec3 drawGrid(in vec2 p){
  vec3 col;
  vec2 fraction=1.-2.*abs(fract(p)-.5);
  float vw=fwidth(p.x)*1.;
  float hw=fwidth(p.y)*1.;
  // 网格线
  col=mix(col,vec3(.3),smoothstep(vw,vw*.9,fraction.x));
  col=mix(col,vec3(.3),smoothstep(hw,hw*.9,fraction.y));
  // col=mix(col,vec3(1.,.3,.4),smoothstep(fwidth(p.x)*2.,fwidth(p.x)*1.95,abs(p.x)));
  // col=mix(col,vec3(1.,.3,.4),smoothstep(fwidth(p.y)*2.,fwidth(p.y)*1.95,abs(p.y)));
  return col;
}

vec3 drawCurve(in vec2 p,in vec3 col){
  float y=sin(p.x);
  float w=fwidth(p.x)*2.;
  y=1.-exp(-100.*abs(y));
  y=.8+.2*cos(150.*y);
  y=sin(10.*sin(y+20.));
  vec2 pos=vec2(p.x,y);
  col=mix(col,vec3(1.,0.,.8314),smoothstep(w,w*.9,length(p-pos)));
  return col;
}

vec3 test(in vec2 p,in vec3 col){
  
  float a=iTime*40.;
  float d,e,f,g=1./40.,h,i,r,q;
  
  e=400.*(p.x*.5+.5);
  f=400.*(p.y*.5+.5);
  i=200.+sin(e*g+a/150.)*20.;
  d=200.+cos(f*g/2.)*18.+cos(e*g)*7.;
  r=sqrt(pow(abs(i-e),2.)+pow(abs(d-f),2.));
  q=f/r;
  e=(r*cos(q))-a/2.;
  f=(r*sin(q))-a/2.;
  d=sin(e*g)*176.+sin(e*g)*164.+r;
  h=((f+d)+a/2.)*g;
  i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.)*(r+h/3.);
  h=sin(f*g)*144.-sin(e*g)*212.*p.x;
  h=(h+(f-e)*q+sin(r-(a+h)/7.)*10.+i/4.)*g;
  i+=cos(h*2.3*sin(a/350.-q))*184.*sin(q-(r*4.3+a/12.)*g)+tan(r*g+h)*184.*cos(r*g+h);
  i=mod(i/5.6,256.)/64.;
  if(i<0.)i+=4.;
  if(i>=2.)i=4.-i;
  d=r/350.;
  d+=sin(d*d*8.)*.52;
  f=(sin(a*g)+1.)/2.;
  col=vec3(f*i/1.6,i/2.+d/13.,i)*d*p.x+vec3(i/1.3+d/8.,i/2.+d/18.,i)*d*(1.-p.x);
  return col;
  
}

vec3 drawArcLine(in vec2 p,vec3 col){
  float a=iTime*40.;
  float d,e,f,g=1./40.,h,i,r,q;
  
  e=400.*(p.x*.5+.5);
  f=400.*(p.y*.5+.5);
  i=200.+sin(e*g+a/150.)*20.;
  d=200.+cos(f*g/2.)*18.+cos(e*g)*7.;
  r=sqrt(pow(abs(i-e),2.)+pow(abs(d-f),2.));
  q=f/r;
  e=(r*cos(q))-a/2.;
  f=(r*sin(q))-a/2.;
  d=sin(e*g)*176.+sin(e*g)*164.+r;
  h=((f+d)+a/2.)*g;
  i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.)*(r+h/3.);
  // h=sin(f*g)*144.-sin(e*g)*212.*p.x;
  // h=(h+(f-e)*q+sin(r-(a+h)/7.)*10.+i/4.)*g;
  // i+=cos(h*2.3*sin(a/350.-q))*184.*sin(q-(r*4.3+a/12.)*g)+tan(r*g+h)*184.*cos(r*g+h);
  // i=mod(i/5.6,256.)/64.;
  // if(i<0.)i+=4.;
  // if(i>=2.)i=4.-i;
  // d=r/350.;
  // d+=sin(d*d*8.)*.52;
  // f=(sin(a*g)+1.)/2.;



  col=vec3(f*i/1.6,i/2.+d/13.,i)*d*p.x+vec3(i/1.3+d/8.,i/2.+d/18.,i)*d*(1.-p.x);
  return col;
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){
  
  vec3 col;
  vec2 p=fixuv(fragCoord);
  vec2 cen=vec2(.5,.5);
  col=drawGrid(p);
  float d=sdCircle(p,.25);
  col=(d>0.)?vec3(.9,.6,.3):vec3(.65,.85,1.);
  col*=abs(sin(d*10.));
  col*=abs(cos(d*30.));
  col=mix(col,vec3(1.),1.-smoothstep(0.,.01,abs(d)));
  // col=test(p,col);
  col=drawArcLine(p,col);
  // col = vec3(d);
  // d*=sin(d)*30.;
  // col=mix(col,vec3(1.,0.,.8314),d);
  fragColor=vec4(col,1.);
}